<?php

include "bootstrap.php";

abstract class BeObject {

  /**
   * This function inits the beobject framework.<br />
   * It's used as the autoload function, registered by spl_autoload_register.
   * @param string $classname The required class.
   */
  public static function init($classname) {
    $rootpath = dirname(__FILE__);

    if ($rootpath == null) {
      throw new BeObjectException("The beObject root path is undefined.");
    } else {
//    var_dump("in");
      foreach (self::$namespaces as $key => $array) {
//        var_dump($classname);
        if (in_array(strtolower($classname), $array)) {
//          var_dump("found");
          $class = substr($classname, strrpos($classname, "\\") + 1);
          $classpath = preg_replace("{classname}", $class, $key);
//          var_dump($rootpath . "/" . strtolower($classpath));
          require_once $rootpath . "/" . strtolower($classpath);
        }
      }
    }
  }

  /** @var array The namespaces => classes. */
  private static $namespaces = array(
      "exceptions/classname.class.php" => array(
          "beobject\exceptions\arithmeticexception",
          "beobject\exceptions\arrayindexoutofboundsexception",
          "beobject\exceptions\beobjectexception",
          "beobject\exceptions\classcastexception",
          "beobject\exceptions\classnotfoundexception",
          "beobject\exceptions\eofexception",
          "beobject\exceptions\\filenotfoundexception",
          "beobject\exceptions\illegalargumentexception",
          "beobject\exceptions\illegalstateexception",
          "beobject\exceptions\indexoutofboundsexception",
          "beobject\exceptions\ioexception",
          "beobject\exceptions\malformedurlexception",
          "beobject\exceptions\\nosuchelementexception",
          "beobject\exceptions\nullpointerexception",
          "beobject\exceptions\numberformatexception",
          "beobject\exceptions\beobjectruntimeexception",
          "beobject\exceptions\unknownhostexception",
          "beobject\exceptions\\validationexception",
          "beobject\exceptions\businessexception"),
      "io/classname.class.php" => array(
          "file",
          "folder",
          "streamreader",
          "streamwriter"),
      "io/interfaces/classname.interface.php" => array(
          "ifile",
          "ifolder",
          "istreamreader",
          "istreamwriter",
          "iio"),
      "primitive/classname.class.php" => array(
          "beobject\primitive\string",
          "beobject\primitive\integer",
          "beobject\primitive\char",
          "beobject\primitive\\float",
          "beobject\primitive\boolean"),
      "net/classname.class.php" => array(
          "\httppost",
          "socket"),
      "net/interfacesclassname.interface.php" => array(
          "isocket"),
      "mvc/classname.class.php" => array(
          "beobject\mvc\controller",
          "beobject\mvc\model",
          "beobject\\mvc\\view",
          "enginemodel",
          "beobject\\mvc\\validatorhelper"),
      "mvc/interfaces/classname.interface.php" => array(
          "beobject\mvc\ivalidation",
          "beobject\mvc\icrud",
          "beobject\mvc\icontroller",
          "beobject\mvc\iserializable"),
      "utils/classname.class.php" => array(
          "script",
          "beobject\utils\arraylist",
          "datetimeparser",
          "dateutils",
          "bcmath",
          "ctype",
          "iniparser",
          "mcrypt",
          "stringutils",
          "cracker",
          "math"),
      "utils/interfaces/classname.interface.php" => array(
          "iarraylist",
          "ictype"),
      "utils/accounting/classname.class.php" => array(
          "swiftcode"),
      "utils/accounting/interfaces/classname.interface.php" => array(
          "iswiftcode"),
      "web/classname.class.php" => array(
          "beobject\\web\\template",
          "beobject\\web\session",
          "cookie",
          "beobject\\web\json",
          "serverutility",
          "beobject\\web\uploadedfile",
          "uri",
          "httputility",
          "postedfile",
          "rss",
          "rssitem",
          "urlinformation"),
      "web/mail/classname.class.php" => array(
          "beobject\\web\mail\mailmessage",
          "mailattachment",
          "beobject\\web\mail\smtpmail"),
      "sql/classname.class.php" => array(
          "mssql",
          "beobject\sql\mysql",
          "beobject\sql\dbconnector",
          "odbclink",
          "sqlserver"),
      "sql/interfaces/classname.class.php" => array(
          "isqlserver"),
      "servers/classname.class.php" => array(
          "apache",
          "configurator",
          "iis",
          "ldap",
          "nsapi",
          "server"),
      "servers/classname.class.php" => array(
          "configurator"),
      "classname.class.php" => array(
          "beobject\object"));

}

?>
